/*
 * @Author: c
 * @Date: 2023-12-06 02:14:14
 * @LastEditTime: 2024-01-07 21:43:43
 * @LastEditors: c
 * @Description: 
 * @FilePath: \music-web-backend\src\core\menus\menus.controller.ts
 * https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Body, Controller, Delete, Get, Param, ParseIntPipe, Post, Put, Query } from '@nestjs/common';
import { CreateMenuDto } from './dto/create-menu.dto';
import { MenuQuery } from './dto/search-menu.dto';
import { UpdateMenuDto } from './dto/update-menu.dto';
import { MenusService } from './menus.service';

@Controller('menus')
export class MenusController {
  constructor(private readonly menusService: MenusService) { }


  /**
   * 菜单-查询列表
   * @returns 
   */
  @Get("")
  public listMenus(@Query() query: MenuQuery) {

    return this.menusService.listMenus(query)
  }
  /**
   * 菜单-侧边栏路由列表
   * @returns 
   */
  @Get("routes")
  public listRoutes() {

    return this.menusService.listRoutes()
  }

  /**
   * 菜单-新增
   * @param createMenuDto 
   * @returns 
   */
  @Post()
  create(@Body() createMenuDto: CreateMenuDto) {
    return this.menusService.create(createMenuDto);
  }

  /**
   * 菜单-下拉列表
   * @returns 
   */
  @Get("options")
  listMenuOptions() {
    return this.menusService.listMenuOptions();
  }

  /**
   * 菜单-查询单条菜单数据
   * @param id 菜单id
   * @returns 
   */
  @Get(':id/form')
  findOne(@Param('id',ParseIntPipe) id: number) {
    return this.menusService.findOne(id);
  }

  /**
   * 菜单-修改单条菜单数据
   * @param id 菜单id
   * @param updateMenuDto 需要修改的数据
   * @returns 
   */
  @Put(':id')
  update(@Body() updateMenuDto: UpdateMenuDto) {
    return this.menusService.update(updateMenuDto);
  }

  /**
   * 菜单-通过id删除单条数据
   * @param id 菜单id
   * @returns 
   */
  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.menusService.remove(+id);
  }
}
